home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / HoW Developer’s Kit 1.2 / HoWSample / HoWSample Help / HoWSample Help.rsrc / STR#_1029.txt < prev    next >
Encoding:
Text File  |  1994-10-17  |  9.0 KB  |  365 lines

  1. 
  2.  
  3. 
  4.  
  5. @
  6.  
  7. @
  8.  
  9. √•Client-Server Relations
  10.  
  11. 
  12.  
  13. 
  14.  
  15. This section explains how a client conducts its relations with the help
  16.  
  17. server, with the help of the HoWLib client interface library.
  18.  
  19. 
  20.  
  21. 
  22.  
  23. 
  24.  
  25. 
  26.  
  27. xThe Client Engine
  28.  
  29. 
  30.  
  31. The interface, described in the next subsection, consists of two utility
  32.  
  33. functions, HoWFindHelpFile and HoWOpen, and three client engine
  34.  
  35. functions, HoWRegister, HoWDisplay, and HoWDeregister.  Your
  36.  
  37. application will generally find its help file and register on entry, display
  38.  
  39. in response to menu, mouse, and key events, and deregister on exit.
  40.  
  41. Apart from that, the only requirement is to call AEProcessAppleEvent
  42.  
  43. when you receive any high-level event that isn‚Äôt known not to be an Apple
  44.  
  45. event, which is generally good practice.
  46.  
  47. (Click this hot button to hear what famous Apple product doesn‚Äôt play by
  48.  
  49. the rules.)
  50.  
  51. 
  52.  
  53. 
  54.  
  55. If your program is not an application, it cannot use client engine functions.
  56.  
  57. It can call HoWFindHelpFile to find its help file if it is separate, and it can
  58.  
  59. call HoWOpen to tell the server to open the help file (starting the server if
  60.  
  61. necessary).  It cannot communicate with the server using tags, neither
  62.  
  63. for display nor for Help events.
  64.  
  65. 
  66.  
  67. When you register, you have the option of starting the server
  68.  
  69. immediately, or deferring until the first display.  Unless the server‚Äôs
  70.  
  71. availability is critical to your application, you will usually choose the
  72.  
  73. latter, less obnoxious, option.
  74.  
  75. 
  76.  
  77. The client engine handles the rest of the relationship between client and
  78.  
  79. server.  Your application doesn‚Äôt have to care where the server is, or
  80.  
  81. whether it‚Äôs running already, or what to do if the user exits the server
  82.  
  83. while your application is running.  The client engine, contained in a
  84.  
  85. purgeable code segment named ‚ÄúHoWLib,‚Äù manages these details for you.
  86.  
  87. If the server is started by some other method while your application is
  88.  
  89. running, the engine senses this, and makes sure that the server adds your
  90.  
  91. application to its Help menu.  The engine also takes care of Help events by
  92.  
  93. invoking your handler, if you have one.
  94.  
  95. 
  96.  
  97. If you call HoWDisplay when the server is not started, and the server
  98.  
  99. can‚Äôt be found on any mounted volume, the engine posts an alert, offering
  100.  
  101. to save the help text as a TeachText document.  If the user agrees, the
  102.  
  103. engine creates the file and opens it automatically.  If the file would be too
  104.  
  105. large for TeachText to open, the engine breaks it into several files and
  106.  
  107. puts them in a new folder.
  108.  
  109. 
  110.  
  111. 
  112.  
  113. 
  114.  
  115. xCasual Displays
  116.  
  117. 
  118.  
  119. HoWSample is a very simple client application which demonstrates good
  120.  
  121. client practices.  Whenever the user selects the main Help menu item or
  122.  
  123. presses the Help key, it calls HoWDisplay with ‚Äútag‚Äù set to 0, or if a
  124.  
  125. dialog is open, some tag value appropriate to the cursor location.
  126.  
  127. Subsidiary items in the Help menu cause calls to HoWDisplay with other
  128.  
  129. tag values, demonstrating how a client can index the help file.
  130.  
  131. 
  132.  
  133. 
  134.  
  135. HoWSample also demonstrates how you can implement context-sensitive
  136.  
  137. help using casual displays.  The ‚Äúcasual‚Äù argument to the HoWDisplay
  138.  
  139. function is always false when HoWSample calls it in reaction to a direct
  140.  
  141. user action.  HoWSample requests a casual display whenever the user
  142.  
  143. selects a menu item or clicks on a dialog item.  Setting ‚Äúcasual‚Äù to true
  144.  
  145. makes the call more of a hint to the server, and less of an order.  This
  146.  
  147. mechanism allows the client to use the server‚Äôs optional ‚Äúfollow‚Äù mode,
  148.  
  149. effectively taking control of the help display.
  150.  
  151. 
  152.  
  153. Specifically, casual displays are different in the following ways:  First,
  154.  
  155. they do not start the server if it isn‚Äôt running.  Second, they do not bring
  156.  
  157. the server into the foreground.  Third, they are ineffective if the server
  158.  
  159. is not already displaying the client‚Äôs help file.  Fourth, they are
  160.  
  161. ineffective if the user has not selected the ‚Äúfollow‚Äù option in the
  162.  
  163. server‚Äôs Preferences dialog.
  164.  
  165. 
  166.  
  167. 
  168.  
  169. 
  170.  
  171. xHoWLib Client Interface Library Functions
  172.  
  173. 
  174.  
  175. This subsection describes exactly what the HoWLib functions do, and how
  176.  
  177. and when to call them, quoting from the C header file.  You may want to
  178.  
  179. follow along in the HoWSample source code as you read these function
  180.  
  181. descriptions.
  182.  
  183. 
  184.  
  185. 
  186.  
  187. 
  188.  
  189. /* The Help event handler receives an event ID which is the negative of
  190.  
  191. the tag associated with the clicked text. */
  192.  
  193. typedef pascal void (*HoWHandlerProcPtr) (short id);
  194.  
  195. 
  196.  
  197. 
  198.  
  199. 
  200.  
  201. /* Find the help file referenced by the 'alis' resource with ID "aliasResID"
  202.  
  203. in the resource file with reference number "preferencesFileRefNum", or
  204.  
  205. in the resource file with reference number "applicationFileRefNum" if the
  206.  
  207. resource does not exist in the preferences file or cannot be resolved.  The
  208.  
  209. alias record, possibly changed by UpdateAlias, is written back to the
  210.  
  211. preferences file if possible.  The application file is not changed.
  212.  
  213. Resolution is relative to the application file, so it can take advantage of
  214.  
  215. relative information in the alias resource if present.  If the help file
  216.  
  217. cannot be found by a fast search, one exhaustive search will be done on
  218.  
  219. the alias record in the application file.  A failed exhaustive search is noted
  220.  
  221. in the preferences file so that it is not repeated; this note remains until
  222.  
  223. the preferences file is deleted, or until a later fast search successfully
  224.  
  225. finds the help file.  If you do not maintain a separate preferences file, set
  226.  
  227. both resource file reference numbers to the same value, and the
  228.  
  229. application file will be treated as though it were also the preferences file.
  230.  
  231. */
  232.  
  233. pascal OSErr HoWFindHelpFile (short preferencesFileRefNum,
  234.  
  235.                               short applicationFileRefNum,
  236.  
  237.                               short aliasResID, FSSpecPtr helpFile);
  238.  
  239. 
  240.  
  241. 
  242.  
  243. 
  244.  
  245. /* Register or re-register with the help server.  The help file may be any
  246.  
  247. file, including the main application file.  If the help file has a 'vers'(1)
  248.  
  249. resource, and the version (first word) does not match "version",
  250.  
  251. wrongVersionErr is returned.  If there is no master resource in the help
  252.  
  253. file for the current script's current language, nor for "defaultLanguage",
  254.  
  255. nor for langEnglish, noMasterResErr is returned.  The server will prefer
  256.  
  257. to use its own language over "defaultLanguage".  By re-registering, the
  258.  
  259. client can switch to another help file.  If the server is not already
  260.  
  261. started, and "startServer" is true, HoWRegister will try to start the
  262.  
  263. server, which may result in many OS error codes, as well as
  264.  
  265. noServerApplErr, a non-fatal code returned for your information (see
  266.  
  267. HoWDisplay below).  If the server is not already started, and
  268.  
  269. "startServer" is false (which it should be for most clients), the usual
  270.  
  271. return code is noErr, meaning that the actual registration has been
  272.  
  273. deferred until the first non-casual display (see below) or until the server
  274.  
  275. starts by some other method.  Gestalt checks may result in other error
  276.  
  277. codes listed above; the expected error code under System 6 is
  278.  
  279. noAppleEventsErr.  The Help event handler is optional; pass nil if the
  280.  
  281. client does not support them. */
  282.  
  283. pascal OSErr HoWRegister (const FSSpec *helpFile, short version,
  284.  
  285.                           LangCode defaultLanguage, Boolean startServer,
  286.  
  287.                           HoWHandlerProcPtr handler);
  288.  
  289. 
  290.  
  291. 
  292.  
  293. 
  294.  
  295. /* Display the help file at the indicated tag position.  If "tag" is zero, the
  296.  
  297. last seen position is retained.  If the server is not already started, and
  298.  
  299. "casual" is false, this will attempt to start the server; if the server is
  300.  
  301. absent, the user sees an alert offering to save a readable copy using
  302.  
  303. TeachText and open it for viewing, unless the client is background-only,
  304.  
  305. in which case no alerts appear, and the document is created on the
  306.  
  307. desktop.  A casual display is effective only if the server is started and
  308.  
  309. running in the background, with the "follow" option in effect, and already
  310.  
  311. displaying this client's help file.  A casual display always leaves the client
  312.  
  313. in the foreground; a non-casual display always brings the server to the
  314.  
  315. foreground.  Note that modal dialogs will prevent the server from coming
  316.  
  317. to the foreground unless they are hidden before this call. */
  318.  
  319. pascal OSErr HoWDisplay (short tag, Boolean casual);
  320.  
  321. 
  322.  
  323. 
  324.  
  325. 
  326.  
  327. /* Deregister with the help server.  If the client fails to deregister
  328.  
  329. before it exits, the server will deregister it automatically. */
  330.  
  331. pascal OSErr HoWDeregister (void);
  332.  
  333. 
  334.  
  335. 
  336.  
  337. 
  338.  
  339. /* Launch the help server, if necessary, to open and display the given
  340.  
  341. help file.  This method is suggested for use by programs which are not
  342.  
  343. applications; applications should use HoWRegister instead (see above).  If
  344.  
  345. the server is absent, a TeachText copy is created on the desktop and
  346.  
  347. opened (as for a background-only application calling HoWDisplay).  Version
  348.  
  349. checking is not performed, and the current script's current language is
  350.  
  351. always used.  This may be called by 'INIT' logic in control panels or
  352.  
  353. extensions, because it uses the Notification Manager; allow 5000 bytes
  354.  
  355. when calculating the system heap requirement for your 'sysz' resource.
  356.  
  357. */
  358.  
  359. pascal OSErr HoWOpen (const FSSpec *helpFile);
  360.  
  361. 
  362.  
  363. 
  364.  
  365.